package com.ddyx.service.user.app.system.controller;

import com.ddyx.common.base.controller.BaseController;
import com.ddyx.service.product.api.entity.Goods;
import com.ddyx.service.product.api.feign.RemoteProductClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.validation.Valid;

/**
 * <p>
 *      测试管理模块  调用远程服务两种方式
 * </p>
 * author: agula
 * since: 2019-07-31  13:42
 */
@Validated
@Api(value = "测试管理模块", tags = "测试管理")
@RestController
@RequestMapping("/demo")
public class DemoController extends BaseController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    private RemoteProductClient remoteProductClient;//远程商品服务

    @ApiOperation(value="测试调用远程接口", notes="测试调用远程接口test。")
    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public Object test(@Valid @PathVariable Integer ProductId) {
        Goods product = remoteProductClient.ProductInfo(ProductId);
        return successResult(product);
    }

    @ApiOperation(value="测试调用远程接口", notes="测试调用远程接口test2。")
    @RequestMapping(value = "/test2", method = RequestMethod.POST)
    public Object test2(@Valid @PathVariable Integer ProductId) {
        Goods product = restTemplate.getForObject("http://localhost:9001/product/api/product/getProductInfo" + ProductId, Goods.class);
        return successResult(product);
    }


}
